﻿package ${web.packageName};

import javax.annotation.Resource;
import cn.demoncat.util.lang.entity.Result;
import cn.demoncat.util.web.annotation.GetJsonMapping;
import cn.demoncat.util.web.annotation.PostJsonMapping;
import cn.demoncat.util.web.annotation.RestControllerMapping;
import cn.demoncat.util.mybatis.plus.Query;
import cn.demoncat.util.mybatis.plus.constant.OrderConstant;

import ${entity.fullName};
import ${service.packageName}.${entity.name}Service;

/** 
 * ${entity.comment}
 *
 * @author ${entity.author}
 *
 * @since ${entity.time}
 */
@RestControllerMapping("${entity.url}")
public class ${entity.name}Controller{

    @Resource
    private ${entity.name}Service ${entity.simpleName}Service;

    /**
     * 列表
     *
     * @param id
     * @param pageNum
     * @param pageSize
     * @return
     *
     * @author ${entity.author}
     * @since ${entity.time}
     */
    @GetJsonMapping("/list")
    public Result list(${entity.idAttr.type} id, Integer pageNum, Integer pageSize){
        <#if entity.hasSort>
        return Result.success(${entity.simpleName}Service.findPage(new Query<${entity.name}>().eq("id", id), pageNum, pageSize, OrderConstant.SORT_ASC));
        <#else>
        return Result.success(${entity.simpleName}Service.findPage(new Query<${entity.name}>().eq("id", id), pageNum, pageSize, OrderConstant.ID_DESC));
        </#if>
    }

    /**
     * 详情
     *
     * @param id
     * @return
     *
     * @author ${entity.author}
     * @since ${entity.time}
     */
    @GetJsonMapping("/info")
    public Result info(${entity.idAttr.type} id){
        return Result.success(${entity.simpleName}Service.getById(id));
    }

    /**
	 * 添加
	 *
	 * @param data
	 * @return
	 *
	 * @author ${entity.author}
	 *
	 * @since ${entity.time}
	 */
	@PostJsonMapping("/add")
	public Result add(${entity.name} data){
	    return ${entity.simpleName}Service.add(data);
	}

	/**
     * 修改
     *
     * @param data
     * @return
     *
     * @author ${entity.author}
     *
     * @since ${entity.time}
     */
    @PostJsonMapping("/upd")
    public Result upd(${entity.name} data){
        return ${entity.simpleName}Service.upd(data);
    }

	/**
	 * 删除
	 *
	 * @param id
	 * @return
	 *
	 * @author ${entity.author}
	 * @since ${entity.time}
	 */
	@GetJsonMapping("/del")
	public Result del(${entity.idAttr.type} id){
	    return ${entity.simpleName}Service.del(id);
	}

    <#if entity.hasSort>
    /**
     * 排序
     *
     * @param id
     * @param sort
     * @return
     *
     * @author ${entity.author}
     * @since ${entity.time}
     */
    @GetJsonMapping("/sort")
    public Result sort(${entity.idAttr.type} id, Long sort){
        return ${entity.simpleName}Service.sort(id, sort);
    }
    </#if>
}